#include "OptionsDialog.h"
#include "../Tools/Settings.h"

OptionsDialog::OptionsDialog(QWidget *parent)
	: QDialog(parent)
{
	setupUi(this);

	connect(_optionSectionsListWidget,
			SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
			this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*)));

	// go to first property page
	_optionSectionsListWidget->setCurrentRow(0);
	
	loadOptions();
}

 OptionsDialog::~OptionsDialog()
{
}

void OptionsDialog::accept()
{
	QDialog::accept();

	// Common property page
	Settings.setAuthorName(_authorLineEdit->text());
	Settings.setLicense(_licenseLineEdit->text());
	Settings.setCopyright(_copyrightLineEdit->text());
}

void OptionsDialog::loadOptions()
{
	// Common property page
	_authorLineEdit->setText(Settings.getAuthorName());
	_licenseLineEdit->setText(Settings.getLicense());
	_copyrightLineEdit->setText(Settings.getCopyright());
}

void OptionsDialog::changePage(
	QListWidgetItem *current, 
	QListWidgetItem *previous)
{
	if (!current)
		current = previous;
	
	// switch current property page
	_optionsStackedWidget->setCurrentIndex(
		_optionSectionsListWidget->row(current));
}
